<template>
  <div>
    <!--    :inline="true"-->
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <div><h1 style="text-align: center">{{this.$route.query.title}}</h1></div>
      <el-form-item label="所处车场:" prop="mcid">
        <el-select v-model="formData.mcid" placeholder="请选择所处车场所处车场" clearable :style="{width: '100%'}"
                   @visible-change="getCarsHomeList">
          <el-option v-for="(item, index) in carshomeapilist" :key="index" :label="item.chname" :value="item.chid"
                     :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商户编号:" prop="code">
        <el-input v-model="formData.code" placeholder="请输入商户编号" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="商户名称:" prop="merchantName">
        <el-input v-model="formData.merchantName" placeholder="请输入商户名称" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="账户:" prop="user.username">
        <el-input v-model="formData.user.username" placeholder="请输入账户" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="密码:" prop="user.password">
        <el-input v-model="formData.user.password" placeholder="请输入密码" clearable show-password
                  :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="手机号:" prop="mobile">
        <el-input v-model="formData.mobile" placeholder="请输入手机号" :maxlength="11" show-word-limit clearable
                  prefix-icon='el-icon-mobile' :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="金额:" prop="balance">
        <el-input v-model="formData.balance" placeholder="请输入金额" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="可透支余额:" prop="credit">
        <el-input v-model="formData.credit" placeholder="请输入可透支余额" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="充值折扣:" prop="discount">
        <el-input v-model="formData.discount" placeholder="请输入充值折扣" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="状态:" prop="status">
        <el-switch v-model="formData.status" active-text="启用" inactive-text="禁用" :active-value='1' :inactive-value='0'></el-switch>
      </el-form-item>
      <el-form-item label="备注:" prop="remark">
        <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注"
                  :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>

import {
  addManagement,
  updateManagement,
  getCarsHomeApi,
} from "@/api/modules/merchat/merchatm/merchat";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        user: {},
      },
      rules: {},
      //车场集合
      carshomeapilist: [],
    }
  },
  computed: {},
  watch: {},
  mounted() {
  },
  created() {
    this.getCarsHomeList();
    if (this.$route.query.data !=null){
      this.formData = this.$route.query.data;
    }
  },
  methods: {
    getCarsHomeList() {
      getCarsHomeApi().then(response => {
        this.carshomeapilist = response.rows;
      }).catch(err => {
        alert("车场模块掉线")
      });
    },
    submitForm() {
      if (this.$route.query.data != null) {
        updateManagement(this.formData).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.resetForm()
        });
      } else {
        addManagement(this.formData).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.resetForm()
        });
      }
    },
    resetForm() {
      this.$store.dispatch('tagsView/delAllViews',this.$router);
      this.$router.push("sys-merchant")
    },
  }
}

</script>
<style>
</style>
